package com.wceManage.beans;

import java.io.Serializable;
import java.sql.Timestamp;
import java.util.List;

/**
 * 资源表
 */
public class SysMenu implements Serializable {

    private static final long serialVersionUID = -51877232753L;

    private Long menuId; //编号

    private String name; //资源名称

    private String iconcls; //图标

    private Integer orderNum; //排序

    private String target; //目标

    private String url; //资源路径

    private Integer type; //资源类型

    private Boolean isShow; //是否在菜单中显示

    private String permission; //权限标识

    private SysMenu parent;    // 父级菜单

    private String perms; // 所有父级编号

    private Timestamp createDate; // 创建时间

    private Timestamp updateDate; // 修改时间

    private Long userId;
    private Long roleId;

    private String descr; //描述

    private Integer sys = 0;//是否系统菜单

    public SysMenu() {
        super();
        this.orderNum = 30;
        this.isShow = true;
    }

    public SysMenu(Long menuId) {
        super();
        this.menuId = menuId;
    }

    public Long getMenuId() {
        return menuId;
    }

    public void setMenuId(Long menuId) {
        this.menuId = menuId;
    }

    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name == null ? null : name.trim();
    }
    public String getIconcls() {
        return iconcls;
    }
    public void setIconcls(String iconcls) {
        this.iconcls = iconcls == null ? null : iconcls.trim();
    }

    public Integer getOrderNum() {
        return orderNum;
    }

    public void setOrderNum(Integer orderNum) {
        this.orderNum = orderNum;
    }

    public String getTarget() {
        return target;
    }
    public void setTarget(String target) {
        this.target = target == null ? null : target.trim();
    }
    public String getUrl() {
        return url;
    }
    public void setUrl(String url) {
        this.url = url == null ? null : url.trim();
    }
    public Integer getType() {
        return type;
    }
    public void setType(Integer type) {
        this.type = type == null ? null : type;
    }
    public Boolean getIsShow() {
        return isShow;
    }
    public void setIsShow(Boolean isShow) {
        this.isShow = isShow;
    }
    public String getPermission() {
        return permission;
    }
    public void setPermission(String permission) {
        this.permission = permission == null ? null : permission.trim();
    }

    public SysMenu getParent() {
        return parent;
    }

    public void setParent(SysMenu parent) {
        this.parent = parent;
    }

    public Long getParentId() {
        return parent != null && parent.getMenuId() != null ? parent.getMenuId() : 0;
    }

    public String getPerms() {
        return perms;
    }

    public void setPerms(String perms) {
        this.perms = perms;
    }

    public String getDescr() {
        return descr;
    }

    public void setDescr(String descr) {
        this.descr = descr;
    }

    public Long getUserId() {
        return userId;
    }

    public void setUserId(Long userId) {
        this.userId = userId;
    }

    public Long getRoleId() {
        return roleId;
    }

    public void setRoleId(Long roleId) {
        this.roleId = roleId;
    }

    public static Long getRootId(){
        return 1L;
    }

    public Timestamp getCreateDate() {
        return createDate;
    }

    public void setCreateDate(Timestamp createDate) {
        this.createDate = createDate;
    }

    public Timestamp getUpdateDate() {
        return updateDate;
    }

    public void setUpdateDate(Timestamp updateDate) {
        this.updateDate = updateDate;
    }

    public Integer getSys() {
        return sys;
    }

    public void setSys(Integer sys) {
        this.sys = sys;
    }

    public static void sortList(List<SysMenu> list, List<SysMenu> menuList, Long parentId, boolean cascade) {
        for (int i = 0; i < menuList.size(); i++) {
            SysMenu e = menuList.get(i);
            if (e.getParent()!=null && e.getParent().getMenuId()!=null
                    && e.getParent().getMenuId().longValue()== parentId.longValue() ){
                list.add(e);
                if (cascade){
                    // 判断是否还有子节点, 有则继续获取子节点
                    for (int j = 0; j < menuList.size(); j++) {
                        SysMenu child = menuList.get(j);
                        if (child.getParent()!=null && child.getParent().getMenuId()!=null
                                && child.getParent().getMenuId().longValue() == e.getMenuId().longValue()){
                            sortList(list, menuList, e.getMenuId(), true);
                            break;
                        }
                    }
                }
            }
        }
    }
}